package com.heima.wemedia.controller.v1;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController {


    @Autowired
    private WmUserService wmUserService;


    /**
     * 根据传递名字查询自媒体用户是否存在
     * @param name
     * @return
     */
    @GetMapping("/findByName/{name}")
    public ResponseResult findByName(@PathVariable("name") String name){
        //根据名字获取自媒体端对象
        WmUser user = wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
        return ResponseResult.okResult(user);
    }


    /**
     * 添加自媒体用户
     * @return
     */
    @PostMapping("/save")
    public ResponseResult addWmUser(@RequestBody WmUser wmUser){
        wmUserService.save(wmUser);
        return ResponseResult.okResult(wmUser);
    }



}
